package com.example.apiproject.controller;

import com.example.apiproject.entity.FeedBack;
import com.example.apiproject.service.FeedBackService;
import com.example.apiproject.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/feedBack")
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    /**
     * 新增
     * @param request
     * @param images
     * @param content
     * @return
     */
    @PostMapping("/add")
    public R add(HttpServletRequest request, @RequestParam List<String> images, String content){
      return R.ok().put("result",feedBackService.insert(request,images,content))  ;
    }

    /**
     * 更新
     * @param feedBack
     * @return
     */
    @PutMapping("/update")
    public R update(@RequestBody FeedBack feedBack){
        return R.ok().put("result",feedBackService.update(feedBack));
    }

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/all")
    public R queryAll(){
        return R.ok().put("result",feedBackService.queryAll());
    }
    /**
     * 查询某用户的反馈
     * @param request
     * @return
     */
    @GetMapping("/own")
    public R getByUserId(HttpServletRequest request){
        return R.ok().put("result",feedBackService.getByUserId(request));
    }

    /**
     * 查询待处理或者已处理的反馈
     * @param status
     * @return
     */
    @GetMapping("/{status}")
    public R queryByStatus(@PathVariable Integer status){
        return R.ok().put("result",feedBackService.queryByStatus(status));
    }


    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public R deleteById(Integer id){
        return R.ok().put("result",feedBackService.delete(id));
    }
}
